import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//用于响应组件中的动作
const actions = {
    increase(context, value){
        context.commit('increase',value)
        console.log(this, '')
    },
    decrease(context, value){
        context.commit('decrease',value)
    },
}
//用于操作state里面的数据
const mutations = {
    increase(state, value){
        state.sum += value
    },
    decrease(state, value){
        state.sum -= value
    },
    increaseOdd(state, value){
        state.sum += state.sum%2===1?value:0
    },
    increaseWait(state, value){
        setTimeout(()=>{
            state.sum += value
        },1000)
    },
}
//用于存储数据
const state = {
    sum:0,
}
//用于加工state的数据
const getters = {
    bigSum(state){
        return state.sum*10
    },
}
export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters,
})
